<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Работа с заказом</title>
    <link rel="stylesheet" href="resources/css/main.css"/>
    <link rel="stylesheet" href="resources/css/stylesheet.css"/>
    <style type="text/css">
    </style>
</head>
<body>
<f:view>
<h:form>

<%-- -------------- Сообщение об ошибки -------------- --%>
<jsp:include page="messages.jsp"/>

<h:panelGrid columns="1" cellpadding="0" cellspacing="0" styleClass="full">
    <rich:panel styleClass="full">
        <h:panelGrid columns="2">
            <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                <h:outputText value="Менеджер"/>
                <h:outputText value="#{OrderBean.order.manager.fio}"/>

                <h:outputText value="Клиент"/>
                <h:outputText value="#{OrderBean.order.client.companyName}"/>

                <h:outputText value="Дата"/>
                <h:outputText value="#{OrderBean.order.reservationDate}"/>

                <h:outputText value="Статус"/>
                <h:outputText value="#{OrderBean.order.orderStateAsString}"/>
            </h:panelGrid>
            <h:panelGrid columns="2">
                <h:outputText value="Доставка"/>
                <h:outputText value="#{OrderBean.order.deliveryTypeAsString}"/>

                <h:outputText value=""/>
                <h:outputText value="#{OrderBean.order.deliveryAddress}"/>

                <h:outputText value=""/>
                <h:outputText value="#{OrderBean.order.deliverySum}"/>
            </h:panelGrid>
            <h:panelGrid columns="4" cellpadding="0" cellspacing="0">
                <h:outputText value="Действия" styleClass="b"/>
                <a4j:commandLink value="Вернуться к списку заказов" action="#" oncomplete="document.location='orders'"/>
                <a4j:commandLink value="Согласовать" action="#{OrderBean.validateOrder}"/>
                <a4j:commandLink value="Оформить" action="#{OrderBean.doSaveOrder}"/>
                <a4j:commandLink value="Удалить" action="#{OrderBean.deleteOrder}"/>
            </h:panelGrid>
            <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                <a4j:commandLink value="Корзина" onclick="document.location='OrderPage.jsf'"/>
                <a4j:commandLink value="Каталог" onclick="document.location='ManagerGoodsPage.jsf'"/>
            </h:panelGrid>
        </h:panelGrid>
    </rich:panel>

    <rich:dataTable value="#{OrderBean.orderItemList}" var="item" styleClass="full" rowKeyVar="row" id="tdlOrderItems">
        <rich:column>
            <f:facet name="header">
                <h:outputText value="№"/>
            </f:facet>
            <h:outputText value="#{row+1}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="о.е."/>
            </f:facet>
            <h:outputText value="#{item.good.name}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Применимость"/>
            </f:facet>
            <h:outputText value="#{item.good.pr}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Количество"/>
            </f:facet>
            <h:outputText value="#{item.count} шт"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Цена"/>
            </f:facet>
            <h:outputText value="#{item.good.price}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Количество"/>
            </f:facet>
            <h:inputText value="#{OrderBean.orderItemsCount[item.id]}"
                         required="true" requiredMessage="Введите количество изменяемого товара"
                         converterMessage="Количество изменяемого товара должно быть числом"
                         style="width:100px;"/>
            <h:outputText value="шт."/>
            <a4j:commandLink value="изменить" action="#{OrderBean.updateOrderItem}" reRender="tdlOrderItems">
                <a4j:actionparam name="updateId" assignTo="#{OrderBean.orderItem.id}" value="#{item.id}"/>
            </a4j:commandLink>
        </rich:column>

        <rich:column>
            <a4j:commandLink value="Удалить" action="#{OrderBean.deleteOrderItem}" reRender="tdlOrderItems">
                <a4j:actionparam name="deleteOrderItem" assignTo="#{OrderBean.orderItem.id}" value="#{item.id}"/>
            </a4j:commandLink>
        </rich:column>
        <f:facet name="footer">
            <h:outputText value="ИТОГО:"/>
        </f:facet>
    </rich:dataTable>

</h:panelGrid>
<%--<a4j:commandButton value="Сохранить" style="top" action="#{OrderBean.saveOrder}"/>--%>


</h:form>
</f:view>
</body>
</html>
